﻿using System;
using AdvancedTool;
using static System.Console;
namespace DiskToolSDK.Basic
{
    /// <summary>
    /// 控制台用户操作类
    /// </summary>
    public class ConsoleUserInterface : IUserInterface
    {
        ConsoleInput input = new ConsoleInput();

        [Obsolete]
        public object RequestCustomInput(params object[] args)
        {
            throw new NotImplementedException();
        }

        bool fontcolorcheck(Object[] obs)
        {
            if (obs.Length == 2)
            {

                bool a1 = obs[0].GetType().Equals(typeof(string));
                bool a2 = false;
                string ename = obs[1].GetType().FullName;
                if (ename != null)
                {
                    if (ename == typeof(ConsoleColor).FullName)
                    {
                        a2 = true;
                    }
                }
                return a1 && a2;
            }
            return false;
        }

        int argCheck(Object[] ob)
        {
            if (fontcolorcheck(ob))
                return 1;

            else
                return -1;
        }

        /// <summary>
        /// (string,ConsoleColor)参数格式可进行色彩文字输出
        /// </summary>
        /// <param name="objs"></param>
        public void RequestCustomOutPut(params object[] objs)
        {
            int t = argCheck(objs);
            if (t == 1)
            {
                ConsoleColor old = Console.ForegroundColor;
                Console.ForegroundColor = (ConsoleColor)objs[1];
                Write(objs[0].ToString());
                Console.ForegroundColor = old;
            }
        }

        public int RequestIntInput(int min, int max)
        {
            return input.ReadInt(min, max);
        }

        public double RequestNumberInput(double min, double max)
        {
            return input.ReadDouble(min, max);
        }

        public void RequestOutPut(string text)
        {
            WriteLine(text);
        }

        public string RequestTextInput()
        {
            return System.Console.ReadLine();
        }

    }

}
